//
//  UIView+Radius.m
//  SulitLoanDemo
//
//  Created by 虞嘉伟 on 2025/2/20.
//  
  

#import "UIView+Radius.h"

@implementation UIView (Radius)

- (void)roundTopCornerRadius:(CGFloat)radius {
    // 创建 UIBezierPath，只对上部两个角切圆角
    UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight; // 选择顶部左右两个角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                                   byRoundingCorners:corners
                                                         cornerRadii:CGSizeMake(radius, radius)];
    
    // 创建 CAShapeLayer
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    
    // 将 CAShapeLayer 设置为 UIView 的 mask
    self.layer.mask = maskLayer;
}

- (void)roundBottomCornerRadius:(CGFloat)radius {
    // 创建 UIBezierPath，只对下部两个角切圆角
    UIRectCorner corners = UIRectCornerBottomLeft | UIRectCornerBottomRight; // 选择顶部左右两个角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                                   byRoundingCorners:corners
                                                         cornerRadii:CGSizeMake(radius, radius)];
    
    // 创建 CAShapeLayer
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    
    // 将 CAShapeLayer 设置为 UIView 的 mask
    self.layer.mask = maskLayer;
}

@end
